<template>
	<view class="container">
		<!-- 全选按钮区 -->
		<label class="radio">
			<!-- checked对用值来自store 中checkedall -->
			<radio color="#009d00" :checked="checkedall" @click="choose" /><text>全选</text>
		</label>
		<!-- 商品总价 -->
		<view class="goods-count">
			<text class="count">总价：{{totalprice}}</text>
		</view>
		<!-- 结算按钮区 -->
		<view class="btn-count" @click="login">
			<!-- 
			同总价
			结算后的商品数量  绑定  选中商品的total
			   1.getters -  goodscount
			    选中商品.reduce((s,v)=>s+=v.goods_count)
			   2.当前组件映射  
			      computed     ...mapGetters("m_car",["goodscount"])
			   3.结算({{goodscount}})  
			 -->
			结算({{checkedcount}})
		</view>


	</view>
</template>

<script>
	// 从store映射
	import {
		mapGetters,
		mapState
	} from "vuex"
	export default {
		name: "my-count",
		data() {
			return {
				amountcount: 0
			};
		},
		computed: {
			...mapState("m_car", ["checkedall"]),
			...mapGetters("m_car", ["totalprice", "checkedcount"])
		},
		methods: {
			// 单击“结算”后
			login() {
				// 获取服务提供商信息  promise对象
				// 两种方式
				//  promise.then(success=>success).catch(err=>err)
				//  promise  优化 访问  async...await 
				// console.log(uni.getProvider({
				// 	service:'oauth'
				// }));
				this.getproviderinfo()
				// 获取用户相关信息  promise对象
				// console.log(uni.getUserInfo());
				this.getuserinfos()
				// 完成登录操作 promise
				// console.log(uni.login());
				this.userlogin()

			},


			//   返回数组[异常信息对象，用户所需信息对象]
			async getproviderinfo() {
				const res = await uni.getProvider({
					service: 'oauth'
				})
				console.log(res);
			},
			// 获取用户微信的详细信息
			async getuserinfos() {
				const res = await uni.getUserInfo()
				console.log(res);
			},
			// 返回code对象
			async userlogin() {
				const res = await uni.login()
				console.log(res);
				if (res[1].errMsg == "login:ok") {
					uni.switchTab({
						url: "/pages/wode/wode"
					})
				}
			},
			// 全选取消
			choose(e) {
				console.log(e);
				// this.$store.commit("m_car/updatecarstate",)
				// 根据本组件的checkedall

				this.$store.commit("m_car/updatecarstate", !this.checkedall)
				// this.checkedall = !this.checkedall
				this.amountcount = this.totalprice

			}
		}
	}
</script>

<style lang="scss">
	.container {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 50px;
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 14px;

		.radio {
			display: flex;
			align-items: center;
		}

		.goods-count {
			.count {
				color: #c00000;
			}
		}

		.btn-count {
			height: 50px;
			min-width: 100px;
			background-color: #c00000;
			color: #fff;
			line-height: 50px;
			text-align: center;
		}
	}
</style>